#!/bin/bash -e

function info() {
echo Usage: `basename $0` '[-l class_list -d path] beta_test'
exit 1
}

while getopts  ":p:f:l:d:" opt; do
	case  $opt  in
		p) out_prefix=$OPTARG;;
		f) suffix=$OPTARG;;
        l) class_list=$OPTARG;;
        d) path=$OPTARG;;
		*) info;;
	esac
done
shift $(($OPTIND - 1))


if [ $# -lt 1 ]; then info; fi

. $var

class_list=${class_list:=$data/meth/class_list}
path=${path:=$data/meth/b450k_class}

cat $class_list |cut -f2,3 |grep -v '^#'|sed '/^$/d'> $out_prefix.class_list

IFS=$'\n'
:>$out_prefix.head
j=0
for i in `cat $out_prefix.class_list`; do
    class_name=`echo $i |cut -f1`
    train=$path/`echo $i |cut -f2`
    ((j+=1))
    train_pre.py -p$out_prefix.$class_name.$j -c $class_name $train $1

    sed 1q $out_prefix.$class_name.$j.train_sub_for_test >> $out_prefix.head
    sed -i 1d $out_prefix.$class_name.$j.train_sub_for_test
    echo $class_name $train $j
done

head -1 $out_prefix.head > $out_prefix.head1
cat $out_prefix.head1 $out_prefix.*.train_sub_for_test > $out_prefix.train_sub_for_test.txt

rm $out_prefix.head1 $out_prefix.*.train_sub_for_test

. $cmd_done